package com.advaita.license;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JList;
import javax.swing.ListModel;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.AbstractListModel;
import javax.swing.BoxLayout;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JTabbedPane;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JTextField;

public class MainFrame {

	private JFrame frame;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainFrame window = new MainFrame();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainFrame() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	@SuppressWarnings("serial")
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 909, 522);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);

		final TestPanel testPanel = new TestPanel();
		testPanel.setBounds(45, 40, 231, 156);
		frame.getContentPane().add(testPanel);

		TestPanel2 testPanel2 = new TestPanel2(this);
		testPanel2.setBounds(66, 231, 231, 191);
		testPanel2
				.addPropertyChangeListener("child", new ChildUpdateListener());
		frame.getContentPane().add(testPanel2);

		JButton btnMainFrameButton = new JButton("Main Frame Button");
		btnMainFrameButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				TestPanel.SetText("From Main");
			}
		});
		btnMainFrameButton.setBounds(309, 79, 123, 23);
		frame.getContentPane().add(btnMainFrameButton);
	}

	public class ChildUpdateListener implements PropertyChangeListener {
		public void propertyChanged(PropertyChangeEvent e) {
			TestPanel.SetText("From Panel");
		}

		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			TestPanel.SetText("From Panel");
		}
	}

	public static void ButtonClicked(String text) {
		TestPanel.SetText(text);
	}
}
